<script setup lang="ts">
import homeFooter from '@/components/homeFooter.vue'
import rewardCard from '@/components/rewardCard.vue'
import NewCard from '@/components/NewCard.vue'
import ActivityComponent from '@/components/ActivityComponent.vue'
import { SESSION_LAST_CODE, SESSION_MEMBER_INFO, VUE_APP_BASE_API } from '@/utils/baseConfig'
import { ref, onMounted } from 'vue'
import { post, get } from '@/utils/service'
const code = localStorage.getItem(SESSION_LAST_CODE)
const banners = ref([])
const newAgentCustomerRewrod = ref({})
const actActivity = ref({})
const bussiHandCarImages = ref([]) // 首页交车车图片
const bussiHandCarState = ref(false) // 首页交车车图片
const homeNews = ref([]) // 主页新闻列表
const homeNewState = ref(false) // 主页新闻列表状态
const openMinaState = ref(false)
onMounted(async () => {
  try {
    get('/bussiBannerWechatNew/queryJsonWechat', { code: code }).then((res) => {
      if (res.code == 0) {
        const data = res.data
        banners.value = data.map((item) => ({
          ...item,
          picture: VUE_APP_BASE_API + item.picture,
          title: item.title,
          dbid: item.dbid,
        }))
      } else {
        console.log('未获取到banner信息')
      }
    })
    post('/corporateCultureWechatNew/queryWechatAgentTopNew', {
      code: code,
    }).then((res) => {
      newAgentCustomerRewrod.value = res.data
    })
    get('/actActivityWechatNew/queryWechatAgentTopNew', {
      code: code,
    }).then((res) => {
      res.data.frontPicture = VUE_APP_BASE_API + res.data.frontPicture
      actActivity.value = res.data
    })
    get('/bussiHandCarImageWechatNew/queryHomeWehcat', {
      code: code,
    }).then((res) => {
      if (res.code == 0) {
        bussiHandCarState.value = true
        bussiHandCarImages.value = res.data.map((item) => ({
          ...item,
          picture: VUE_APP_BASE_API + item.picture,
        }))
      } else {
        bussiHandCarState.value = false
      }
    })
    get('/corporateCultureWechatNew/queryWechatNews', {
      code: code,
    }).then((res) => {
      if (res.code == 0) {
        homeNewState.value = true
        homeNews.value = res.data.map((item) => ({
          ...item,
          picture: VUE_APP_BASE_API + item.picture,
        }))
      } else {
        homeNewState.value = false
      }
    })
  } catch (error) {
    console.log('onMounted error:' + error)
  }
})
function openUrl(item: object) {
  window.location.href = item.url
}
function openMinia() {
  openMinaState.value = true
}
</script>
<template>
  <div style="max-width: 1280px; margin: 0 auto">
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white" height="200">
      <van-swipe-item>
        <img :src="VUE_APP_BASE_API + '/images/vue/1.jpg'" alt="" width="100%" height="100%" />
      </van-swipe-item>
      <van-swipe-item>
        <img :src="VUE_APP_BASE_API + '/images/vue/1.jpg'" alt="" width="100%" height="100%" />
      </van-swipe-item>
      <van-swipe-item>
        <img :src="VUE_APP_BASE_API + '/images/vue/2.jpg'" alt="" width="100%" height="100%" />
      </van-swipe-item>
      <van-swipe-item>
        <img :src="VUE_APP_BASE_API + '/images/vue/3.jpg'" alt="" width="100%" height="100%" />
      </van-swipe-item>
      <van-swipe-item v-for="item1 in banners" v-bind:key="item1.dbid">
        <img :src="item1.picture" alt="" width="100%" height="100%" @click="openUrl(item1)" />
      </van-swipe-item>
    </van-swipe>
    <van-grid square>
      <van-grid-item
        to="/recommendCustomer"
        :icon="VUE_APP_BASE_API + '/images/vue/recommendCustomer.png'"
        text="推荐客户"
      >
      </van-grid-item>
      <van-grid-item
        :icon="VUE_APP_BASE_API + '/images/vue/receptionRecord.png'"
        text="保养邀约"
        to="/bookingRepair"
      />
      <van-grid-item
        to="/tryCar"
        :icon="VUE_APP_BASE_API + '/images/vue/tryCar.png'"
        text="预约试驾"
      />
      <van-grid-item
        :icon="VUE_APP_BASE_API + '/images/vue/oldCarChange.png'"
        text="旧车置换"
        to="/oldCarChange"
      />
      <van-grid-item
        :icon="VUE_APP_BASE_API + '/images/vue/yearApproval.png'"
        text="年审预约"
        to="/examined"
      />
      <van-grid-item
        :icon="VUE_APP_BASE_API + '/images/vue/political.png'"
        text="推荐政策"
        to="/rewardRole"
      />
      <van-grid-item
        :icon="VUE_APP_BASE_API + '/images/vue/spreadCode.png'"
        text="推广码"
        to="/mySpreadQrCode"
      />
      <van-grid-item
        :icon="VUE_APP_BASE_API + '/images/vue/pointShop.png'"
        @click="openMinia"
        text="积分商城"
      />
    </van-grid>
    <rewardCard :item="newAgentCustomerRewrod" :show-tile-state="true"></rewardCard>

    <ActivityComponent
      :item="actActivity"
      :show-tile-state="true"
      v-if="actActivity.dbid > 0"
    ></ActivityComponent>

    <!--取消喜悦交车功能
     <div class="loveHandCarContent" v-if="bussiHandCarState">
      <van-row>
        <van-col span="8" class="ryCardTitleOp">喜悦交车</van-col>
        <van-col span="8"></van-col>
        <van-col span="8" style="text-align: right">
          <div class="ryCardTitleOpMore" to="/bussiHandCarImages">
            <RouterLink to="/bussiHandCarImages" class="router-link-active">更多</RouterLink>
          </div>
        </van-col>
      </van-row>
      <div class="imgContain">
        <HandCarImageItemComponent
          v-for="carImage in bussiHandCarImages"
          :item="carImage"
          :key="carImage.dbid"
        ></HandCarImageItemComponent>
      </div>
    </div> -->
    <div class="loveHandCarContent" v-if="homeNewState">
      <van-row>
        <van-col span="8" class="ryCardTitleOp">公司新闻</van-col>
        <van-col span="8"></van-col>
        <van-col span="8" style="text-align: right">
          <div class="ryCardTitleOpMore" to="/newList">
            <RouterLink to="/newList" class="router-link-active">更多</RouterLink>
          </div>
        </van-col>
      </van-row>
      <NewCard
        :item="homeNew"
        v-for="homeNew in homeNews"
        :show-tile-state="false"
        :key="homeNew.dbid"
      ></NewCard>
    </div>
    <br />
    <br />
    <br />
  </div>
  <van-popup v-model:show="openMinaState" round :style="{ padding: '14px' }">
    <div style="width: 100%; margin: auto 0; text-align: center; padding: 30px; display: grid">
      <VanImage :src="VUE_APP_BASE_API + '/images/vue/ruiyiShop.png'"></VanImage>
      <p style="text-align: center">长按识别或扫码进入</p>
    </div>
  </van-popup>
  <homeFooter></homeFooter>
</template>
<style></style>
